package com.granada.controller.sys;

import com.granada.behaviour.neutral.UserRoleWithNeutralBehavior;
import com.granada.service.UserRoleWithNeutralService;
import com.granada.service.base.UserRoleService;
import com.granada.utils.DataResult;
import com.granada.aop.annotation.LogAnnotation;
import com.granada.vo.req.UserRoleOperationReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassName: UserRolerController
 * TODO:类文件简单描述
 * @Author: 小霍
 * @CreateDate: 2019/9/19 11:38
 * @UpdateUser: 小霍
 * @UpdateDate: 2019/9/19 11:38
 * @Version: 0.0.1
 */
@RequestMapping("/sys")
@RestController
@Api(tags = "组织管理-用户和角色关联接口")
public class SysUserRoleController {
    @PostMapping("/user/role")
    @ApiOperation(value = "修改或者新增用户角色接口")
    @LogAnnotation(title = "用户和角色关联接口",action = "修改或者新增用户角色")
    public DataResult operationUserRole(@RequestBody @Valid UserRoleOperationReqVO vo) throws Exception{
        UserRoleService userRoleService = new UserRoleWithNeutralService(
                new UserRoleWithNeutralBehavior()
        );
        userRoleService.addBatch(vo.getRoleIds(), vo.getUserId());
        return DataResult.success();
    }
}
